package com.swak.boot.config.fx;

import java.util.Properties;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertiesPropertySource;

import com.swak.config.setting.Settings;

/**
 * 本地配置，读取本地的配置文件
 * 
 * @author 618lf
 */
public class SettingsEnvPostProcessor implements EnvironmentPostProcessor, Ordered {

	@Override
	public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
		Settings settings = Settings.intSettings();
		Properties properties = new Properties();
		properties.putAll(settings.getConfig());
		PropertiesPropertySource propertiesPropertySource = new PropertiesPropertySource("fx.settings", properties);
		environment.getPropertySources().addFirst(propertiesPropertySource);
	}

	@Override
	public int getOrder() {
		return LOWEST_PRECEDENCE - 1000;
	}
}
